<?php 
include 'load.php';

$register_error = false;
$register_success = false;

$uname = $_POST['username'];
$pass = $_POST['password1'];

if (preg_match("/^[\w\-\.]+@[\w\-]+(\.\w+)+$/", $uname)){
	$resu = $snsdb->get_var("select count(*) from sns_user where username='$uname'");
	if($resu == 0){
		$id = $snsdb->insert("sns_user", array('username'=>$uname, 'password'=>md5($pass), 'status'=>1, 'create_time'=> gmdate("Y-m-d\TH:i:s\Z")));
		$register_success = true;
	}else{
		$register_error = "您的Email已被注册，请选择一个其他的Email";
	}
}else{
	$login_error = "您输入的Email地址不正确，请检查后重新输入！";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>注册账号--微博营销工具</title>
        <link href="<?php echo $root_path;?>style.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="<?php echo $root_path;?>js/jquery.js"></script>
        <script type="text/javascript" >
			function submitCheck(){
				var uname = $("#username").val();
				var pass1 = $("#password1").val();
				var pass2 = $("#password2").val();

				var reg = /^[\w\-\.]+@[\w\-]+(\.\w+)+$/;
				if(!reg.test(uname)){
					$("#reg_msg").html("请输入正确的邮箱地址！");
					$("#reg_msg").show();
					return false;
				}
				if(pass1.length <=5 ){
					$("#reg_msg").html("请至少输入6位密码！");
					$("#reg_msg").show();
					return false;
				}

				if(pass1 != pass2){
					$("#reg_msg").html("两次输入的密码不同，请重新输入！");
					$("#reg_msg").show();
					return false;
				}
				
				return true;
			}
		</script>
    </head>
    
    <body id="logincont">
    	<div id="container">
        	<img src="<?php echo $root_path;?>images/container_top.gif" width="880" height="12" style="float:left" />
            	<h1>RSS源新浪微博定时发布系统</h1>
                <div id="login">
                	<img src="<?php echo $root_path;?>images/login_top.jpg" height="9" width="514" style="float:left" />
                		<span id="loginname">注册账号</span>
                		
                		<?php if($register_success){
                		?>
                			<span id="reg_msg" style="background: #A5C639; float:left; color: white;padding: 10px;width: 400px;font-size: 16px;
                        		-webkit-border-radius: 6x;-moz-border-radius: 6px;border-radius: 6px; margin: 20px;">
                        		您的的账号： <?php echo $uname;?> 已注册成功！<br />
                        		现在就去<a href="<?php echo $root_path;?>login.php">登录</a>
                        	</span>
                		<?php
                		}?>
                		
                        <form method="post" action="" id="loginform" onsubmit="return submitCheck()" <?php if ($register_success) echo 'style="display: none;"' ?>>
                        	<span id="reg_msg" style="background: #FF6D37; color: white;padding: 10px;width: 400px;font-size: 16px;
                        		-webkit-border-radius: 6x;-moz-border-radius: 6px;border-radius: 6px;<?php if ($register_error) echo "display: block"; else  echo "display: none;";?>">
                        		<?php echo $register_error;?>
                        	</span>
                        	<span>
                            	<label for="username">Email:</label>
                            	<input type="text" name="username" id="username" class="inputbg" value="<?php echo $uname;?>" />
                            </span>
                            <span>
                                <label for="password">密码:</label>
                                <input type="password" name="password1" id="password1" class="inputbg" />
                            </span>
                            <span>
                                <label for="password">重复:</label>
                                <input type="password" name="password2" id="password2" class="inputbg" />
                            </span>
                            <input type="submit" value="提交" id="submit" />
                        </form>
                    <img src="<?php echo $root_path;?>images/login_buttom.jpg" height="9" width="514" style="float:left" />
                </div>
        	<img src="<?php echo $root_path;?>images/container_buttom.gif" width="880" height="12" style="float:left;" />
        </div>
    </body>
</html>
